Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
Google Script - How to add a function in value="" in HTML with a JS function?

So it's my first post ever on StackOverflow, so sorry if I tell something weird:

So, I would like to display the date from the function Today() in my input with the id "file_name" (so, it will be like a default value):

webAppBoot.html

<!DOCTYPE html>
<html>

<head>
  <?!= include('WebAppBoot-css'); ?>
</head>

<body>
    <form>
        <div class="input-field col s6">
          <input id="file_name" type="text" class="validate">
          <label for="file_name">File name</label>
        </div>
    </form>
<?!= include('WebAppBoot-js'); ?>
</body>

</html>

index.gs

function doGet(request) {
  return HtmlService.createTemplateFromFile('WebAppBoot')
      .evaluate();
}

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
      .getContent();
}

I know that I can totally write the function Today() from this file WebAppBoot-js.html

<script>
    document.getElementById("file_name").value = google.script.run.Today();    
</script>

But I prefer to add it from this file : functions.gs

  function Today() {
  var today = new Date();
  var dd = String(today.getDate()).padStart(2, '0');
  var mm = String(today.getMonth() + 1).padStart(2, '0')
  var yyyy = today.getFullYear();
  return mm + '/' + dd + '/' + yyyy;
}

So, as I tried, it's not working as you can see: undefined value

But I can still see that the function is working with a Logger.log(Today()) function So, to resume, in definitive, I would like to have that when we open the form:Final result

Can you help me ? Thank you

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda